﻿@using Website.CRUDServices
@using Location = Website.Models.Domain.Location
@using Profile = Website.Models.Domain.Profile
@using Region = Website.Models.Domain.Region
@{
    this.ViewBag.Title = "Network";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var Presentations = this.ViewData["Presentations"] as List<Presentation>;
    var Regions = this.ViewData["Regions"] as List<Region>;
    var Projects = this.ViewData["Projects"] as List<Project>;
    var ProfileView = this.ViewData["Profiles"] as Website.Models.ViewModels.ProfilesView;
    Guid otherId = Guid.Empty;

    // errorhandling
    var errorMsg = new HtmlString(string.Empty);
    if (this.ViewData["ErrorMessage"] != null)
    {
        errorMsg = this.ViewData["ErrorMessage"] as HtmlString;
    }

}
<script type="text/javascript">
    //toggle script
    function toggle(id) {
        if (document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == "") {
            document.getElementById(id).style.display = 'block';
        } else {
            document.getElementById(id).style.display = 'none';
        }
    }
</script>
<script>
    $(function () {
        $("#datepicker").datepicker();
    });
</script>

@using (this.Html.BeginForm())
{
    <div class="error">
        @errorMsg
    </div>
    
    // Product type
    <div class="formBullet">Beskrivelse</div>
    <input type="text" id="ProductType" name="ProductType" />

    // date
    <div class="formBullet">Dato</div>
    <input type="text" id="datepicker" name="datepicker" readonly="readonly" value="" />

    // location
    <div class="formBullet">Lokation</div>
    <div class="formEntry">
        <select name="Location" id="Location">
            <option value="@Guid.Empty">Vælg en lokation</option>
            @foreach (Location loc in ProfileView.Locations.OrderBy(x => x.Name))
            {
                <option value="@loc.ID">@loc.Name</option>
            }
        </select>
    </div>
    
    <div class="formBullet">National eller international</div>
    <div class="formEntry">
        <label><input type="radio" name="IsNational" value="true" checked="checked" />National<br /></label>
        <label><input type="radio" name="IsNational" value="false" />International</label>
    </div>
    
            // Type chooser
    <div class="formBullet">Hvilket type netværk er der tale om?</div>
    <div>
        <input type="radio" name="NetworkType" value="IsNetworkingEvent" checked>Netværksmøde<br />
        <input type="radio" name="NetworkType" value="IsConferenceEvent">Konference<br />
        <input type="radio" name="NetworkType" value="IsDelegationTravel">Delegationsrejse<br />
        <input type="radio" name="NetworkType" value="IsProductLaunch">Produkt lancering<br />
    </div>

            // ownerProjects chooser
    <div class="formBullet">Alle projekter tilknyttet</div>
    <div class="formEntry">
        <select multiple="multiple" name="OwnerProjects" id="OwnerProjects">
            @foreach (Project proj in Projects)
            {
                <option value="@proj.ID">@proj.Name</option>
            }
        </select>
    </div>

            // profiles chooser
    <div class="formBullet">Deltagere</div>
    <div class="formEntry">
        <select multiple="multiple" name="Attendees" id="Attendees">
            @foreach (Profile prof in ProfileView.Profiles)
            {
                <option value="@prof.ID">@prof.Name</option>
            }
        </select>
    </div>



    
    <div class="formBullet">WT Rolle</div>
    <div class="formEntry">
        <select multiple="multiple" name="Roles" id="Roles">
            <option value="Booth">Stand</option>
            <option value="Attendance">Deltagelse</option>
            <option value="Organizer">Arrangør</option>

        </select>
    </div>
    

            // Profiles chooser
    <div class="formBullet">Understøttelse af virksomhedsdeltagelse</div>
    <div class="formEntry">
        <select multiple="multiple" name="SupportForBusinessAttendance" id="SupportForBusinessAttendance">
            @foreach (Profile prof in ProfileView.Profiles)
            {
                <option value="@prof.ID">@prof.Name</option>
            }
        </select>
    </div>

            // Presentations chooser
    <div class="formBullet">Præsentationer</div>
    <div class="formEntry">
        <select multiple="multiple" name="Presentations" id="Presentations">
            @foreach (Presentation pres in Presentations)
            {
                // toggle hidden field for explaining the "Other" choice
                if (pres.Name == "Andet")
                {
                    otherId = pres.ID;
                }

                <option value="@pres.ID">@pres.Name</option>
            }
        </select>
    </div>

    // field for specifying "andet"
    <div class="formEntry open_hidden" id="andet_holder">
        <div class="formBullet">Specificér "Andet"</div>
        <textarea name="Andet"></textarea>
    </div>

    <div class="formBullet">Kommentarer</div>
    <div class="formEntry">
        <textarea name="Commentary"></textarea>
    </div>

    <div class="buttonHolder">
        <input type="submit" value="Opret" />
    </div>
}

<script>
    $(function () {
        $('#SupportForBusinessAttendance').multiSelect();
        $('#Attendees').multiSelect();
        $('#OwnerProjects').multiSelect();
        $('#Roles').multiSelect();

        //choosing "andet" will pop up an additional text-box for input on the subject

        $('#Presentations').multiSelect({
            afterSelect: function (value) {
                if (value == "@otherId.ToString()") {
                    toggle("andet_holder");
                }
            },

            afterDeselect: function (value) {
                if (value == "@otherId.ToString()") {
                    toggle("andet_holder");
                }
            }
        });

    });
</script>
